package model

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Order struct {
	Id          uint           `gorm:"column:id;type:bigint(20) UNSIGNED;comment:主键;primaryKey;not null;" json:"id"`                                     // 主键
	OrderSn     string         `gorm:"column:order_sn;type:varchar(255);comment:订单编号;not null;" json:"order_sn"`                                         // 订单编号
	UserId      uint           `gorm:"column:user_id;type:bigint(20);comment:用户id;not null;" json:"user_id"`                                             // 用户id
	GoodsId     uint           `gorm:"column:goods_id;type:bigint(20);comment:商品id;not null;" json:"goods_id"`                                           // 商品id
	OrderNum    uint           `gorm:"column:order_num;type:int(11);comment:订单数量;not null;" json:"order_num"`                                            // 订单数量
	OrderTotal  float64        `gorm:"column:order_total;type:decimal(10, 2);comment:订单总金额;not null;" json:"order_total"`                                // 订单总金额
	OrderStatus uint           `gorm:"column:order_status;type:tinyint(1) UNSIGNED;comment:1:待支付，2:支付完成，3:支付失败;not null;default:1;" json:"order_status"` // 1:待支付，2:支付完成，3:支付失败
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (o *Order) TableName() string {
	return "order"
}
func (o *Order) CreateOrder() error { //创建订单
	return config.DB.Create(&o).Error
}
